package com.neusoft.neuiotms.dcom.controller.insurance;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.auth.common.bean.UserBean;
import com.neusoft.bizcore.web.dto.result.PageResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultListDTO;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.neuiotms.dcom.dto.insurance.InsuranceRegisterDTO;
import com.neusoft.neuiotms.dcom.service.insurance.InsuranceRegisterService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "重保服务登记")
@RestController
@RequestMapping(value = "/api/w/insurance/register")
public class InsuranceRegisterController {

    @Autowired
    private InsuranceRegisterService registerService;

    @ApiOperation("查询所有重保服务登记")
    @GetMapping
    public ResultListDTO<InsuranceRegisterDTO> index(final Searchable searchable, final UserBean user) {
        return ResultListDTO.success(this.registerService.index(searchable, user));
    }

    @ApiOperation("分页查询重保服务登记")
    @GetMapping("/p")
    public PageResultDTO<InsuranceRegisterDTO> page(final Searchable searchable, final Pageable pageable,
            final UserBean user) {
        return PageResultDTO.success(this.registerService.page(searchable, pageable, user));
    }

    @ApiOperation("新增重保服务登记")
    @PostMapping
    public ResultDTO<InsuranceRegisterDTO> create(@RequestBody final InsuranceRegisterDTO dto, final UserBean user) {
        return ResultDTO.success(this.registerService.create(dto, user));
    }

    @ApiOperation("更新重保服务登记")
    @PutMapping("/{id}")
    public ResultDTO<InsuranceRegisterDTO> update(@PathVariable final Long id,
            @RequestBody final InsuranceRegisterDTO dto,
            final UserBean user) {
        return ResultDTO.success(this.registerService.update(id, dto, user));
    }

    @ApiOperation("更新重保服务登记状态")
    @PutMapping("/release/{id}/{status}")
    public ResultDTO<InsuranceRegisterDTO> update(@PathVariable final Long id,
            @PathVariable final Boolean status) {
        return ResultDTO.success(this.registerService.updateStatus(id, status));
    }

    @ApiOperation("查看重保服务登记")
    @GetMapping("/{id}")
    public ResultDTO<InsuranceRegisterDTO> details(@PathVariable final Long id) {
        return ResultDTO.success(this.registerService.detail(id));
    }

    @ApiOperation("删除重保服务登记")
    @DeleteMapping("/{id}")
    public ResultDTO<Void> delete(@PathVariable final Long id) {
        this.registerService.delete(id);
        return ResultDTO.success();
    }

}
